<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        /*--------------------- 测试结构表达式 ------------------------*/
        let analyticalExpression = function() {
            // 数组解构表达式
            let arr1 = [1,2,3]
            let [a,b,c,d=20] = arr1
            console.log(`数组解构表达式：a = ${a}, b = ${b}, c = ${c}, d = ${d}`)

            // 对象解构表达式不取别名
            let person = {name:"小明", age:24, score:89}
            let {name, age, score, xx = 'jjjj'} = person
            console.log(`对象解构表达式不取别名：name = ${name}, age = ${age}, score = ${score}, xx = ${xx}`)

            // 对象解构表达式取别名
            let person2 = {name2:"小明", age2:24, score2:89}
            let {name2:n, age2:y, score2:s, xx2:x = 'jjjj'} = person2
            console.log(`对象解构表达式取别名：n = ${n}, y = ${y}, s = ${s}, x = ${x}`)

            // 函数解构表达式传参
            let result = fun1([1, 2])
            console.log(`函数解构表达式传参：result = ${result}`)
        }

        let fun1 = function([a,b]) {
            return a + b
        }
    </script>
</head>
<body>
    <button onclick="analyticalExpression()">解构表达式</button>
    
</body>
</html>